home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / dev / lang / sbp3_1e.lzh / MAP.PL < prev    next >
Text File  |  1991-10-31  |  2KB  |  67 lines

  1. /* From the book PROLOG PROGRAMMING IN DEPTH
  2.    by Michael A. Covington, Donald Nute, and Andre Vellino.
  3.    Copyright 1988 Scott, Foresman & Co.
  4.    Non-commercial distribution of this file is permitted. */
  5. /* Modified for Quintus Prolog by Andreas Siebert */
  6.  
  7. /* MAP.PL */
  8.  
  9. /* This file uses the writeln routine in file WRITELN.PL. */
  10. :- ( clause(writeln(_),_) ; consult('writeln.pl') ).
  11.  
  12. map :- color_map([],Solution), writeln(Solution).
  13.  
  14. color_map(Solution,Solution) :-
  15.           \+ remaining(_,Solution).
  16.  
  17. color_map(List,Solution) :-
  18.      remaining(Country,List),
  19.      color(Hue),
  20.      \+ prohibited(Country,Hue,List),
  21.      write(Country),nl,
  22.      color_map([[Country,Hue]|List],Solution).
  23.  
  24. remaining(Country,List) :- country(Country),
  25.                            \+ member([Country,_],List).
  26.  
  27. prohibited(Country,Hue,List) :-
  28.      borders(Country,Neighbor),
  29.      member([Neighbor,Hue],List).
  30.  
  31. borders(Country,Neighbor) :- beside(Country,Neighbor).
  32. borders(Country,Neighbor) :- beside(Neighbor,Country).
  33.  
  34. member(X,[X|_]).
  35. member(X,[_|Y]) :- member(X,Y).
  36.  
  37. /* Only four colors are ever needed */
  38.  
  39. color(red).
  40. color(blue).
  41. color(green).
  42. color(yellow).
  43.  
  44. /* Geographical data for South America. */
  45.  
  46. country(antilles).       country(argentina).
  47. country(bolivia).        country(brazil).
  48. country(columbia).       country(chile).
  49. country(ecuador).        country(french_guiana).
  50. country(guyana).         country(paraguay).
  51. country(peru).           country(surinam).
  52. country(uruguay).        country(venezuela).
  53.  
  54. beside(antilles,venezuela).   beside(argentina,bolivia).
  55. beside(argentina,brazil).     beside(argentina,chile).
  56. beside(argentina,paraguay).   beside(argentina,uruguay).
  57. beside(bolivia,brazil).       beside(bolivia,chile).
  58. beside(bolivia,paraguay).     beside(bolivia,peru).
  59. beside(brazil,columbia).      beside(brazil,french_guiana).
  60. beside(brazil,guyana).        beside(brazil,paraguay).
  61. beside(brazil,peru).          beside(brazil,surinam).
  62. beside(brazil,uruguay).       beside(brazil,venezuela).
  63. beside(chile,peru).           beside(columbia,ecuador).
  64. beside(columbia,peru).        beside(columbia,venezuela).
  65. beside(ecuador,peru).         beside(french_guiana,surinam).
  66. beside(guyana,surinam).       beside(guyana,venezuela).
  67.